<template>
  <div class="panel-container">
    <div class="panel-content">
      <div class="panel-title">地域分布统计</div>
      <BarChart :chartData="chartData" />
      <div class="table">
        <div class="col">
          <div class="th"></div>
          <div class="td" v-if="time.start_time === time.end_time">{{ time.start_time }}</div>
          <div class="td" v-else>{{ time.start_time }} - {{ time.end_time }}</div>
        </div>
        <div class="col" v-for="item in dataList" :key="item[0]">
          <div class="th">{{ item[0] }}</div>
          <div class="td">{{ item[1] }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import BarChart from '@/components/ECharts/BarChart.vue'
import { apiNoticeCountCity } from '@/api/biddingNotice'

export default {
  name: 'Panel3',
  props: {
    time: Object,
  },
  components: { BarChart },
  watch: {
    time: function () {
      this.getData()
    },
  },
  data() {
    return {
      dataList: [],
      chartData: {},
    }
  },
  mounted() {},
  destroyed() {},
  methods: {
    getData() {
      apiNoticeCountCity(this.time).then((res) => {
        const { info } = res
        this.dataList = info
        this.setChartsData(info)
      })
    },
    setChartsData(data) {
      this.chartData = {
        xAxis: data.map((item) => {
          return item[0]
        }),
        series: [
          {
            name: '',
            data: data.map((item) => {
              return item[1]
            }),
          },
        ],
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.table {
  margin-top: 20px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  width: 100%;
  border: 1px solid #dcdfe6;
  .col {
    flex-grow: 1;
    border-right: 1px solid #dcdfe6;
    &:last-child {
      border: none;
    }
    .th {
      border-bottom: 1px solid #dcdfe6;
      color: #333333;
      font-weight: bold;
    }
    .th,
    .td {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 30px;
    }
  }
}
</style>
